<?php
class createLesson extends lesson {
	function __construct($id) {
		parent::__construct($id);
	}
	public function insert($tabla) {
		$arrDatos = $this->data[$tabla];
		$arr_keys = array_keys($arrDatos);
		$values = "";
		$keys = "";
		$query = "INSERT INTO ".$tabla;
		for ($i = 0; $i < count($arr_keys);$i++) {
			$keys .=$arr_keys[$i].",";
			if (is_string($arrDatos[$arr_keys[$i]])) {	$values .= "'".$arrDatos[$arr_keys[$i]]."',"; }
			else { $values .= $arrDatos[$arr_keys[$i]].","; }
		}
		$keys = substr($keys,0,strlen($keys)-1);
		$values = substr($values,0,strlen($values)-1);
		$query .= "(".$keys.") VALUES (".$values.");";
		try {
			mysql_query($query);
			if (1000 < mysql_errno() && mysql_errno() < 2056) throw new Exception("Error al intentar dar de alta el nuevo cliente.");
		} catch (Exception $e) {
			echo mysql_errno(). " : " .mysql_error();
			exit();
		}
		return mysql_insert_id();
	}
	public function getStudents() {
		$query = "SELECT a.id,a.nombre,a.email,a.apellido FROM alumnos a, alumnosxprofesor axp WHERE (a.estado>0) AND (axp.fk_profesor = ".$this->get('clases','fk_profesor').") AND (axp.estado>1) AND (a.id=axp.fk_alumno);";
		$result = mysql_query($query);
		$arr_students = array();
		$i = 0;
		while ($reg = @mysql_fetch_array($result)) {
			$arr_students[$i]['id'] = $reg['id'];
			$arr_students[$i]['nombre'] = $reg['nombre'];
			$arr_students[$i]['apellido'] = $reg['apellido'];
			$arr_students[$i]['email'] = $reg['email'];
			$i++;
		}
		return $arr_students;
	}
	public function addStudentsToLesson($students,$id) {
		foreach ($students as $student_id) {
			$query = 'INSERT INTO alumnosxclase(fk_alumno,fk_grupo,estado,fecha) VALUES ('.(int)$student_id.','.$id.',1,'.time().');';
			mysql_query($query) or die(mysql_error());
		}
	}
}
?>